<?php
/**
 * Description of cache
 * How to Use?
 * 
 * $oCache = new cache;
 * $sCacheName = 'online_players';  name for cache file
 * $lifetime = '120';  in seconds
 * if($oCache->checkCache($sCacheName, $lifetime)) {
 *    $oCache->getCache($sCacheName);
 * } else {
 * 	  $oCache->startCaching();
 *    HERE CONTENT
 *    $oCache->stopCaching($sCacheName);
 * }
 * 
 * @author trambauern
 *
class cache {
	// Der Pfad zu den Cache-Dateien (absolut oder relativ)
	var $sCachePath = '_cache/';
	// Die Dateierweiterung für die Cache-Dateien (z.B. ".cache")
	var $sFileExtension = '.cache';

	function checkCache($filename, $defaulttime) {
		if(file_exists($this->sCachePath.$filename.$this->sFileExtension) && time()-filemtime($this->sCachePath.$filename.$this->sFileExtension)<$defaulttime) {
			return 1;
		} else {
			return 0;
		}
	}
	function getCache($filename) {
		$data =  file_get_contents($this->sCachePath.$filename.$this->sFileExtension);
		echo $data;
	}
	
	function startCaching() {
		ob_start();
	}
	function stopCaching($filename)  {
		$catchContent = ob_get_clean();
		$catchContent = $catchContent;
		$fh = fopen($this->sCachePath.$filename.$this->sFileExtension , "w");
		fputs($fh, $catchContent);
		fclose($fh);
		echo $catchContent;
	}
}
*/
?>
